<%= javascript_include_tag "sharing.js" -%>
<%= javascript_include_tag 'survey_checkbox.js' -%>
<%= stylesheet_link_tag 'survey_ul'%>
<%= stylesheet_link_tag 'faux_table'%>
<% if !@survey_hash.empty? %>
<% if !Survey.all.empty? && !Dataset.all.empty? -%>

<% @survey_search_query="Enter search terms" unless @survey_search_query -%>
<% @survey_search_query= params[:survey_search_query] unless params[:survey_search_query]==nil -%>
	<!-- might be able to upload user surveys in future -->
  <!--<li><%#= icon "new", new_survey_path, "Upload New Survey", nil, "Upload New Survey" %></li>-->
  <!-- <li><%#= icon "view-all", all_files_path, nil, nil, "View All Files" %></li> -->
</ul>
<div class="show_basic" style="padding-right: 2em;">
  <div id="survey_selector">
    <% form_tag(:action => "search_variables") do -%>
      <!-- jquery grid experiment-->
      <%# form_tag(:action => "grid_view") do -%>

      <%= hidden_field_tag "page", 1 -%>
      <%= hidden_field_tag "per_page", 10 -%>
<br/>
      <% if !logged_in? -%>
        <h2>Welcome, guest.  Please select some surveys and search for variables of interest to your research.  You can browse the metadata and see what is inside the MethodBox but only <%= link_to "registered users", signup_url -%> can add variables to their cart and download them.</h2><br/>
      <% else -%>
        <h2>Select some surveys, enter a search term and click the button to find some variables</h2><br/>
      <% end -%>
      <div style="position: relative;background-color:#ACCBE0;padding-top:5px;padding-bottom:5px;padding-left:5px;width:100%;height:60px;">
        <div style="position: absolute; ;top:1em;left:1em"><%= text_field_tag :survey_search_query, @survey_search_query %>
				<%= image_tag (method_to_icon_filename("help"), :size => "25x25", :alt => "Search terms quick guide", :title=>"Search terms quick guide", :onclick => "showPopup('help_box'); return false;",:class=> "help_image") -%>
          <%= submit_tag 'Search selected surveys',:id => "search_button",:onclick => "if (!checkNotEmpty('survey_search_query')) {return false;} else {return true;}" %>
        </div>
		  <% if logged_in? && !@recent_searches.empty? -%>
		  <div style="position: absolute; top:1em;left:30em">
			Recent searches:
		<%= select_tag 'recent searches' ,options_from_collection_for_select(@recent_searches, 'id', 'terms'), :onchange=>"javascript:$('survey_search_query').value = this.options[this.selectedIndex].text" -%>
		</div>
		<% end -%>
        <!-- jquery grid experiment -->
        <%#= submit_to_remote 'submit', 'JQ Grid', {:url=>{:controller => "variables", :action=> "grid_view"}} -%>
        <% if logged_in? -%>
          <div id="cart_button" style="position: absolute; top:1em; right:1em;">
            <%= render :partial => "cart/button" -%>
          </div>
        <% end -%>
        <div style="position: absolute; bottom:0.9em; left:1em;">
			<%#= image_tag ( method_to_icon_filename("help"), :size => "25x25", :alt => "Search terms how to", :title=>"Search terms how to", :onclick => "showPopup('help_box'); return false;") -%>
	
          <%#= link_to "Help", help2_surveys_url, :onclick => "showPopup('help_box'); return false;"%>
          <div id="help_box" style="display: none; z-index: 100; position: absolute;">
            <%= render :partial=>"term_help_popup" %>
          </div>
          Select:
          <%= link_to_function 'All', "$$('input.survey_checkbox').each(function(checkbox){selectDatasets(checkbox, true);})" %>
          ,&nbsp
          <%= link_to_function 'None', "$$('input.survey_checkbox').each(function(checkbox) { selectDatasets(checkbox, false);})" %>
          ,&nbsp
          <%= link_to_function 'Invert selection', "$$('input.survey_checkbox').each(function(checkbox) { selectDatasets(checkbox, !checkbox.checked);})" %>
        </div>
      </div><br/><br/>
<div id="currently_selected_datasets" style="display:none;">Currently selected datasets:</div>
<div id="datasets_list"> 
<%= render :partial => "dataset_list", :locals => { :survey_hash => @survey_hash } -%>
</div>
      <% if @surveys.public_methods.include?("page_count") %>
      <% end %>

      <div class="tabber">
        <% @survey_hash.each_key do |key| -%>
          <div class="tabbertab" title="<%= @survey_hash[key][0].survey_type.name -%>">
            <h3>
              <%= key -%>
            </h3>
            <div>
              <%= render :partial => "single_survey_check", :locals => { :key => key, :collection => @survey_hash, :selected => Array.new, :authorization_for_showing_already_done=>true }  %>
            </div>
          </div>
        <% end -%>
      </div>
      <br class="clear"/><br/>
      <div id="table"></div>
    <% end -%>
  </div>
</div>
<% else %>
<% if logged_in? %>
<% if Survey.all.empty? %>
 <h1>There are no surveys loaded into the methodbox at the moment.</h1>
<p class="center"> Why not <%= link_to "upload a new survey", new_survey_path -%></p>
<% else %>
 <h1>There are no surveys with datasets in the methodbox at the moment. </h1>
<p class="center">Select a survey from the list and add a dataset to it.</p>
<%= render :partial => "survey_list" -%>
<% end -%>
<% else %>
        <h1>There are no surveys loaded into the methodbox at the moment.</h1>
<% end -%>
<% end -%>
<% if !@empty_surveys.empty? %>
<h3>Surveys without any datasets</h3>
<% @empty_surveys.each do |survey| %>
	<%= link_to survey.title, survey_url(survey) -%>
<% end -%>
<% end -%>
<% else %>
<h1>There are no surveys available to view.</h1>
<% end %>
<!-- jquery grid experiment -->
  <%# form_tag(:action => "grid_view") do -%>
  <%#= submit_tag 'Show grid view',:id => "grid_button" %>
  <%# end -%>
